const http = require('http');

const server = http.createServer();

server.on('request',function (req,res) {
    let url = req.url;
    if(url === '/plain'){
        res.setHeader('Content-type','text/plain;charset=utf-8');
        res.end('data 数据');
    }else if (url === '/html') {
        res.setHeader('Content-type','text/html;charset=utf-8');
        res.end('<p>这是数据 <a href="http://www.baidu.com">baidu</a></p>');
    }

});

server.listen(3001,function () {
    console.log('server works,running on port 3001');
});